﻿using System;
using System.Diagnostics;
using System.Threading;
using System.Windows.Automation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ProdControls;

namespace ProdControlsTests {
    [TestClass()]
    public class ProdWindowTests {

        [ClassInitialize]
        public static void Setup(TestContext context) {
            //Start the Winforms Application
            Process.Start("WindowsFormsApplication.exe");

            //Start the WPF Application
            Process.Start("WpfFormTestWindow.exe");

        }

        [ClassCleanup]
        public static void TearDown(){
            foreach (Process _process in Process.GetProcessesByName("WindowsFormsApplication")) {
                _process.Kill();
            }

            foreach (Process _process in Process.GetProcessesByName("WpfFormTestWindow")) {
                _process.Kill();
            }
        }

        [TestMethod]
        public void GetWindowsTitleWinForm(){
            ProdWindow _win = new ProdWindow("Form");
            Assert.AreEqual("Form1",_win.Title);

        }

        [TestMethod]
        public void GetWindowsTitleWpf() {
            ProdWindow _win = new ProdWindow("MainWindow");
            Assert.AreEqual("MainWindow", _win.Title);

        }

        [TestMethod]
        public void ActivateTestWinForm() {
            ProdWindow _win = new ProdWindow("Form1");
            _win.Activate();
        }

        [TestMethod]
        public void ActivateTestWpf() {
            ProdWindow _win = new ProdWindow("MainWindow");
            _win.Activate();
            Thread.Sleep(1000);
            Assert.IsTrue(_win.IsTopmost);
        }



        [TestMethod]
        public void MinimizeTestWinForm() {
            ProdWindow _win = new ProdWindow("Form1");
            _win.Minimize();
            Assert.AreEqual(WindowVisualState.Minimized,_win.WindowVisualState);
        }

        [TestMethod]
        public void MinimizeTestWpf() {
            ProdWindow _win = new ProdWindow("MainWindow");
            _win.Minimize();
            Assert.AreEqual(WindowVisualState.Minimized, _win.WindowVisualState);
        }

        [TestMethod()]
        public void MaximizeTestWinForm() {
            ProdWindow _win = new ProdWindow("Form1");
            _win.Maximize();
            Assert.AreEqual(WindowVisualState.Maximized, _win.WindowVisualState);
        }

        [TestMethod()]
        public void MaximizeTestWpf() {
            ProdWindow _win = new ProdWindow("MainWindow");
            _win.Maximize();
            Assert.AreEqual(WindowVisualState.Maximized, _win.WindowVisualState);
        }

        [TestMethod()]
        public void RestoreTestWinForm() {
            ProdWindow _win = new ProdWindow("Form1");
            _win.Restore();
            Assert.AreEqual(WindowVisualState.Normal, _win.WindowVisualState);
        }

        [TestMethod()]
        public void RestoreTestWpf() {
            ProdWindow _win = new ProdWindow("MainWindow");
            _win.Restore();
            Assert.AreEqual(WindowVisualState.Normal, _win.WindowVisualState);
        }

        [TestMethod()]
        public void ResizeTestWinForm() {
            ProdWindow _win = new ProdWindow("Form1");
            _win.Resize(200,200);
            Assert.AreEqual(200,_win.Width);
            //todo: window closes upon execution
        }

        [TestMethod()]
        public void ResizeTestWpf() {
            ProdWindow _win = new ProdWindow("MainWindow");
            _win.Resize(200, 200);
            Assert.AreEqual(200, _win.Width);
            //todo: window closes upon execution
        }

        [TestMethod()]
        public void MoveTestWinForm() {
            ProdWindow _win = new ProdWindow("Form1");
            _win.Move(500,500);

            //todo: window closes upon execution
            //todo: find assert
        }

        [TestMethod()]
        public void MoveTestWinWpf() {
            ProdWindow _win = new ProdWindow("MainWindow");
            _win.Move(500, 500);
            //todo: window closes upon execution
            //todo: find assert
        }

        [TestMethod()]
        public void RotateTestWinForm() {
            ProdWindow _win = new ProdWindow("Form1");
            _win.Rotate(90);
            //todo: window closes upon execution
            //todo: find assert
        }

        [TestMethod()]
        public void RotateTestWpf() {
            ProdWindow _win = new ProdWindow("MainWindow");
            _win.Rotate(90);
            //todo: window closes upon execution
            //todo: find assert
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void CloseTestWinForm() {
            ProdWindow _win = new ProdWindow("Form1");
            _win.Close();
            ProdWindow _emptyHandle = new ProdWindow("Form1");

        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void CloseTestWpf() {
            ProdWindow _win = new ProdWindow("MainWindow");
            _win.Close();
            ProdWindow _emptyHandle = new ProdWindow("MainWindow");

        }
    }
}